/*
 * chat_mgr.h
 *
 *  Created on: Dec 9, 2013
 *      Author: killerg
 */

#ifndef CHAT_MGR_H_
#define CHAT_MGR_H_

#include "share/patterns.h"

struct client_session_t;

struct chatmgr_t {
    typedef std::shared_ptr<cs::SMsg> sp_msg_t;
    struct delay_msg_t {
        sp_msg_t msg;
        int64_t exclude_playerid = -1;
        int32_t msgsize = 0;
    };

    bool init();
    void destroy();
    void update();

    void add_channel(cs::SMsg* msg, int channel = -1, int64_t exclude_playerid = -1);
    void send_log(sp_player_t player);

    int add(int64_t playerid, client_session_t* sess);
    void remove(int channel, int64_t playerid);

    void broad_msg(sp_msg_t msg, int channel = -1);
    void broad_scroll(const char* content, int channel = -1);
    void broad_system(const char* content, int channel = -1);
    void broad(int32_t msgid, const void* msg, size_t size, int channel = -1, int64_t exclude_playerid = -1);

    struct channel_t {
        int id;
        std::vector<client_session_t*> sess_vec;
        std::unordered_map<int64_t, int> id_map;
        std::list<int> freepos_list;

        std::queue<delay_msg_t> send_queue;
        std::list<delay_msg_t> log;
    };

    ptr_map<int, channel_t*> channel_map;
    int32_t next_channelid = 0;
    list<channel_t*> free_channel;
    int32_t drop_num = 0;
};

#endif /* CHAT_MGR_H_ */
